package unit8.part4;

import javax.swing.*;
import java.awt.*;

public class JCheckBoxAndJRadioButtonTest {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame("测试多选框和单选框");
        jFrame.setBounds(100, 100, 500, 300);
        jFrame.setLayout(new GridLayout(2, 3));

        String[] array = new String[]{"选项A", "选项B", "选项C"};

        for (String item : array) {
            JCheckBox checkBox = new JCheckBox(item);// 多选框
            jFrame.add(checkBox);
            checkBox.isSelected();// 多选项是否被选中
        }

        ButtonGroup buttonGroup = new ButtonGroup();// 选项组
        for (String item : array) {
            JRadioButton radio = new JRadioButton(item);// 单选框
            buttonGroup.add(radio);
            jFrame.add(radio);
            radio.isSelected();// 单选框是否被选中
        }

        jFrame.setVisible(true);
    }
}
